The following methods are available in JavaScript:
abs acos alert anchor asin assign atan back big blink blur bold ceil charAt clear clearTimeout click close confirm cos eval exp fixed floor focus fontcolor fontsize forward getDate getDay getHours getMinutes getMonth getSeconds getTime getTimeZoneoffset getYear go indexOf italics lastIndexOf link log max min open parse pow prompt random round select setDate setHours setMinutes setMonth setSeconds setTimeout setTime setYear sin small sqrt strike sub submit substring sup tan toGMTString toLocaleString toLowerCase toString toUpperCase UTC write writeln
Displays an Alert dialog box with a message and an OK button.
Syntax
alert("message")
The argument message is any string.
Description
Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains.
Applies to
window
Examples
In the following example, the testValue function checks the name entered by a user in the text element of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user of an application to enter a valid value.
function testValue(textElement) {
if (textElement.length > 8) {
alert("Please enter a name that is 8 characters or less")
}
}
You can call the testValue function in the onBlur event handler of a form's text element, as shown in the following example:
Displays a Confirm dialog box with the specified message and OK and Cancel buttons.
Syntax
confirm("message")
The argument message is any string.
Description
Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decison. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.
Applies to
window
Examples
This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application.
function confirmCleanUp() {
if (confirm("Are you sure you want to quit this application?")) {
cleanUp()
}
}
You can call the confirmCleanUp function in the onClick event handler of a form's pushbutton, as shown in the following example: